/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package ejb.entities;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.List;

import javax.persistence.*;

import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author simone
 */
@Entity
@Table(name = "Pacchetto")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Pacchetto.findAll", query = "SELECT p FROM Pacchetto p"),
    @NamedQuery(name = "Pacchetto.findByIdPacchetto", query = "SELECT p FROM Pacchetto p WHERE p.idPacchetto = :idPacchetto"),
    @NamedQuery(name = "Pacchetto.findByName", query = "SELECT p FROM Pacchetto p WHERE p.name = :name"),
    @NamedQuery(name = "Pacchetto.findByPredefinito", query = "SELECT p FROM Pacchetto p WHERE p.predefinito = :predefinito"),
    @NamedQuery(name = "Pacchetto.findByPredicateDate", query = "SELECT p FROM Pacchetto p WHERE (p.dal >= :dateDal OR p.al <= :dateAl) AND p.onSale =:onSale"),
    @NamedQuery(name = "Pacchetto.findByOnSaleInDate", query = "SELECT p FROM Pacchetto p WHERE p.onSale = :onSale AND p.al >= :date")})
public class Pacchetto implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id_pacchetto")
    private Integer idPacchetto;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 255)
    @Column(name = "name")
    private String name;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 255)
    @Column(name = "description")
    private String description;
    @Basic(optional = false)
    @NotNull
    @Column(name = "predefinito")
    private int predefinito;
    @Basic(optional = false)
    @NotNull
    @Column(name = "on_sale")
    private int onSale;
    @Basic(optional = false)
    @NotNull
    @Column(name = "dal")
    @Temporal(TemporalType.TIMESTAMP)
    private Date dal;
    @Basic(optional = false)
    @NotNull
    @Column(name = "al")
    @Temporal(TemporalType.TIMESTAMP)
    private Date al;
    @OneToMany(mappedBy = "fkPacchetto")
    private Collection<Pacchettoprenotato> pacchettoprenotatoCollection;
    @JoinColumn(name = "fk_stanza", referencedColumnName = "id_stanza")
    @ManyToOne(optional = false)
    private Tipostanza fkStanza;

 
    @ManyToMany(cascade = CascadeType.ALL)
    @JoinTable(name = "Comprende_prodotti",
            joinColumns = {@JoinColumn(name = "fk_pacchetto", referencedColumnName = "id_pacchetto")},
            inverseJoinColumns = {@JoinColumn(name = "fk_hotel", referencedColumnName = "id_hotel")})
    private List<Hotel>hotelBelongTo;
    
    @ManyToMany(cascade = CascadeType.ALL)
    @JoinTable(name = "Comprende_prodotti",
            joinColumns = {@JoinColumn(name = "fk_pacchetto", referencedColumnName = "id_pacchetto")},
            inverseJoinColumns = {@JoinColumn(name = "fk_escursioni", referencedColumnName = "id_escursioni")})
    private List<Escursione>tourBelongTo;
       
    @ManyToMany(cascade = CascadeType.ALL)
    @JoinTable(name = "Comprende_prodotti",
            joinColumns = {@JoinColumn(name = "fk_pacchetto", referencedColumnName = "id_pacchetto")},
            inverseJoinColumns = {@JoinColumn(name = "fk_viaggio", referencedColumnName = "id_viaggio")})
    private List<Viaggio>tripBelongTo;
     
    
    
    public Pacchetto() {
        this.hotelBelongTo = new ArrayList<>();
        this.tourBelongTo = new ArrayList<>();
        this.tripBelongTo = new ArrayList<>();
    }
    
    public List<Hotel> getHotelsBelongTo()
    {
        return this.hotelBelongTo;             
    }
    public List<Escursione> getToursBelongTo()
    {
        return this.tourBelongTo;             
    }
    
    public List<Viaggio> getTripBelongsTo()
    {
        return this.tripBelongTo;             
    }
    public Pacchetto(Integer idPacchetto) {
        this.idPacchetto = idPacchetto;
    }

    public Pacchetto(String name, String description, int predefinito, int onSale, Date dal, Date al) {
        this.name = name;
        this.description = description;
        this.predefinito = predefinito;
        this.onSale = onSale;
        this.dal = dal;
        this.al = al;
    }

    public Integer getIdPacchetto() {
        return idPacchetto;
    }

    public void setIdPacchetto(Integer idPacchetto) {
        this.idPacchetto = idPacchetto;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public int getPredefinito() {
        return predefinito;
    }

    public void setPredefinito(int predefinito) {
        this.predefinito = predefinito;
    }

    public int getOnSale() {
        return onSale;
    }

    public void setOnSale(int onSale) {
        this.onSale = onSale;
    }

    public Date getDal() {
        return dal;
    }

    public void setDal(Date dal) {
        this.dal = dal;
    }

    public Date getAl() {
        return al;
    }

    public void setAl(Date al) {
        this.al = al;
    }

    @XmlTransient
    public Collection<Pacchettoprenotato> getPacchettoprenotatoCollection() {
        return pacchettoprenotatoCollection;
    }

    public void setPacchettoprenotatoCollection(Collection<Pacchettoprenotato> pacchettoprenotatoCollection) {
        this.pacchettoprenotatoCollection = pacchettoprenotatoCollection;
    }

    public Tipostanza getFkStanza() {
        return fkStanza;
    }

    public void setFkStanza(Tipostanza fkStanza) {
        this.fkStanza = fkStanza;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idPacchetto != null ? idPacchetto.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Pacchetto)) {
            return false;
        }
        Pacchetto other = (Pacchetto) object;
        if ((this.idPacchetto == null && other.idPacchetto != null) || (this.idPacchetto != null && !this.idPacchetto.equals(other.idPacchetto))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "ejb.entities.Pacchetto[ idPacchetto=" + idPacchetto + " ]";
    }
    
}
